<?

//global $catid = 0;
require("includes/constantesMvial.php");
require("header_inc.php");
if (!getParamInt("catid","")){
	$catid = ID_CAT_COMPRA;
	$fp = 1;
	//logMsg("index.php"," \$fp-> $fp");
}
/*Esta variable es un flag que indica si hay que redireccionar al listado de "subtipos" (es decir las categorias dentro 
 * de un mercado dado)
 * */
$RedirectTipo=getParamInt("redirecttipo",0);

if (($catid == ID_CAT_COMPRA || $catid == ID_CAT_SERVICIOS || $catid == ID_CAT_ALQUILER) && ($RedirectTipo==0)){
	$fp = 1;
	$bannerHid="";
	$isMercado = false;
	//logMsg("index.php"," \$fp-> $fp");
}else{
	//JMR: ID del tipo de operacion para saber que banners mostrar
	$arrayOperacionMercado = getTipoDeOperacionyMercado($catid,$isMercado);
	$isMercado = $arrayOperacionMercado["mercado"]; 
	$bannerHid = $arrayOperacionMercado["operacion"];
}

// Security check
if (file_exists("install.php"))
{
	
	if (!file_exists("admin/config/opt_inc.php"))
	{
		redirect("install.php");
	}
	else 
	{
		print "<p><center><b><font color='red'>SECURITY WARNING</font></b><br />You have not followed our instructions to 	delete install.php
		immediately after install. Leaving this file here is a <u>major</u> security problem and opens your site up
		to wild hacking.</center></p>";	
	}
}

// If we are on the frontpage, write out welcome message along with flags
$tplIndex=new TplLoad;   

$tplIndex->caching = false;
$tplIndex->assign("catname","$lCatName");
$val_string = "";
$tplIndex->assign("index_catid",$catid);
$tplIndex->assign("banner",$lBanner);
$tplIndex->assign("isFrontpage","$fp");
if ($fp && !$set_latest_fp)
$tplIndex->assign("HideLastListFp","1");
$tplIndex->assign("index_nameofsite",$set_sitename);
$tplIndex->assign("index_welcome",formatString(WELCOME_MESSAGE, array("$set_sitename")));
$tplIndex->assign("index_welcome_1",formatString(LA_WELCOME_1, array("$set_sitename")));
$tplIndex->assign("index_welcome_2",formatString(LA_WELCOME_2, array("$set_sitename")));
$tplIndex->assign("index_welcome_91",formatString(LA_WELCOME_LOGGED_1, array($_SESSION['user_name'])));
$tplIndex->assign("index_welcome_92",formatString(LA_WELCOME_LOGGED_2, array($_SESSION['user_name'])));
$tplIndex->assign("member",$_SESSION["valid_user"]);
$tplIndex->assign("premium_picture",$set_premium_picture);
$tplIndex->assign("set_special",$set_special);
$tplIndex->assign("premium_picture",$set_premium_picture);
$tplIndex->assign("set_special",$set_special);
$tplIndex->assign("bannerHid",$bannerHid);
$tplIndex->assign("isMercado",$isMercado);


if ($set_special)
{
	
	$limit=$set_premium_limit;
//	$sql_str = "select ad_title, ad_id from $ads_tbl where ad_is_premium=1 ";
	$sql_str = "select $ads_tbl.ad_title, $ads_tbl.ad_id, IFNULL($pic_tbl.filename,'default.jpg') as filename
          FROM $ads_tbl left join $pic_tbl on $pic_tbl.pic_ad_id = $ads_tbl.ad_id
    	  WHERE 		  
		  (main=1 or mvial_picture.filename is null) and ad_is_premium=1 ";
    
	if ($catid AND $set_special_categories)
		$sql_str.=" AND $ads_tbl.ad_cat_id=$catid";
	if ($set_special_only_frontpage AND $catid)
		$sql_str.=" AND 2<1";
		
	$sql_str.=" $val_string order by $ads_tbl.ad_id desc limit $limit";
	$res_sp = q($sql_str);
	$sp_i=0;
	while ($row_sp=mysql_fetch_array($res_sp))
	{
		$s_title = $row_sp["ad_title"];	
		$s_id = $row_sp["ad_id"];	
		$filename = $row_sp["filename"];
		$filename=ereg_replace("tmb2","tmb1",$filename);
		
		
		$lSpecialAds[$sp_i]["s_title"]=dotString($s_title,$set_special_string_length);
		$lSpecialAds[$sp_i]["s_id"]=$s_id;
		$lSpecialAds[$sp_i]["s_link"]=linkDetail($s_id);
		$lSpecialAds[$sp_i]["filename"]=$filename;
		
		$sp_i++;
	}
	$tplIndex->assign("special_list",$lSpecialAds);	
	
	if ($sp_i==0)
		$tplIndex->assign("size","100");	
	else
		$tplIndex->assign("size","70");	
}
else 
{	
	$tplIndex->assign("size","100");		
}

$tplIndex->display("index.tpl");
include_once("footer_inc.php");
?>
